<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="A very lame cool person">
    <meta name="keyword" content="null">
    <meta name="theme-color" content="#600090">
    <meta name="msapplication-navbutton-color" content="#600090">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#600090">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="alternate" type="application/atom+xml" title="Guanghui" href="/atom.xml">
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.css">
    <title>
        
        Asp.net MVC系列教程7——创建与登录用户相关的接口和实现类｜Guanghui&#39;s blog
        
    </title>

    <link rel="canonical" href="https://wghglory.github.io/2017/02/19/mvc-lesson7/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/blog-style.css">

    <link rel="stylesheet" href="/css/my.css">

    <!-- Pygments Github CSS -->
    <link rel="stylesheet" href="/css/syntax.css">
</head>

<style>

    header.intro-header {
        background-image: url('/images/tag.jpg')
    }
</style>
<!-- hack iOS CSS :active style -->
<body ontouchstart="" class="animated fadeIn">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top " id="nav-top" data-ispost = "true" data-istags="false
" data-ishome = "false" >
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand animated pulse" href="/">
                <span class="brand-logo">
                    Guanghui
                </span>
                's Blog
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <!-- /.navbar-collapse -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>
					
                    
                        
							
                        <li>
                            <a href="/tags/">tags</a>
                        </li>
							
						
                    
                        
							
                        <li>
                            <a href="/works/">my works</a>
                        </li>
							
						
                    

					
                        <li>
                            <a href="https://wghglory.github.io/guanghui.resume/" target="_blank">Resume</a>
                        </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
//    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>

<!-- Main Content -->

<!--only post-->


<img class="wechat-title-img" src="/images/default-post.jpg">


<style>
    
    header.intro-header {
        background-image: url('/images/default-post.jpg');
    }

    
</style>

<header class="intro-header">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <div class="post-heading">
                    <h1>Asp.net MVC系列教程7——创建与登录用户相关的接口和实现类</h1>
                    
                    <span class="meta">
                         作者 Guanghui Wang
                        <span>
                          日期 2017-02-19
                         </span>
                    </span>
                    <div class="tags text-center">
                        
                        <a class="tag" href="/tags/#c#"
                           title="c#">c#</a>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="post-title-haojen">
        <span>
            <!-- Asp.net MVC系列教程7——创建与登录用户相关的接口和实现类 -->
        </span>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">
            <!-- Post Container -->
            <div class="col-lg-8 col-lg-offset-1 col-sm-9 post-container">
                <h1 id="简述"><a href="#简述" class="headerlink" title="简述"></a>简述</h1><p>本文转自<a href="http://yuangang.cnblogs.com并加以整理。" target="_blank" rel="noopener">http://yuangang.cnblogs.com并加以整理。</a> 今天我们创建几个与登录用户相关的数据表的接口和实现类</p>
<h1 id="索引"><a href="#索引" class="headerlink" title="索引"></a>索引</h1><p><a href="/2017/02/14/mvc-lesson1/" target="_blank">Asp.net MVC项目系列教程</a></p>
<h1 id="项目开始"><a href="#项目开始" class="headerlink" title="项目开始"></a>项目开始</h1><h3 id="一、新建登录用户类Account"><a href="#一、新建登录用户类Account" class="headerlink" title="一、新建登录用户类Account"></a>一、新建登录用户类Account</h3><p>之前lesson5我们登录验证直接返回了管理员实体类SYS_USER，但是在实际的后台操作验证中，我们并不需要SYS_USER的许多属性，同时我们需要它的一些扩展属性，我们来新建一个管理员类，来具体的描述这个管理员，我们在Service类库下面新建一个管理类Account.cs</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 通用用户登录类，简单信息</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Account</span></span></span><br><span class="line"><span class="class">    &#123;</span></span><br><span class="line">        <span class="meta">#region Attribute</span></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 主键</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">int</span> Id &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 姓名</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="built_in">string</span> Name &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 登录的用户名</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="built_in">string</span> LogName &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 登录密码</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="built_in">string</span> PassWord &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 是否管理员</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">bool</span> IsAdmin &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 用户头像</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> <span class="built_in">string</span> Face_Img &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 用户主部门</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> Domain.SYS_DEPARTMENT DptInfo &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 用户所在部门集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_DEPARTMENT&gt; Dpt &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 权限集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_PERMISSION&gt; Permissions &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 角色的集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_ROLE&gt; Roles &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 用户岗位集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_POST_USER&gt; PostUser &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 用户可操作的模块集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_MODULE&gt; Modules &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="meta">#endregion</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="二、修改我们的用户管理接口IUserManage"><a href="#二、修改我们的用户管理接口IUserManage" class="headerlink" title="二、修改我们的用户管理接口IUserManage"></a>二、修改我们的用户管理接口IUserManage</h3><p>修改用户管理接口IService/SysManage/IUserManage.cs. 添加几个方法：根据用户ID获取本职部门名称、 删除用户、根据用户构造用户基本信息、从Cookie中获取用户信息</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// &lt;summary&gt;</span></span><br><span class="line"><span class="comment">/// 根据用户ID获取本职部门名称</span></span><br><span class="line"><span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">GetUserDptName</span><span class="params">(<span class="keyword">int</span> id)</span></span>;</span><br><span class="line"><span class="comment">/// &lt;summary&gt;</span></span><br><span class="line"><span class="comment">/// 删除用户</span></span><br><span class="line"><span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">Remove</span><span class="params">(<span class="keyword">int</span> userId)</span></span>;</span><br><span class="line"><span class="comment">/// &lt;summary&gt;</span></span><br><span class="line"><span class="comment">/// 根据用户构造用户基本信息</span></span><br><span class="line"><span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line"><span class="function">Account <span class="title">GetAccountByUser</span><span class="params">(Domain.SYS_USER user)</span></span>;</span><br><span class="line"><span class="comment">/// &lt;summary&gt;</span></span><br><span class="line"><span class="comment">/// 从Cookie中获取用户信息</span></span><br><span class="line"><span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line"><span class="function">Account <span class="title">GetAccountByCookie</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>
<h3 id="三、我们分别创建几个关联表的接口和实现类"><a href="#三、我们分别创建几个关联表的接口和实现类" class="headerlink" title="三、我们分别创建几个关联表的接口和实现类"></a>三、我们分别创建几个关联表的接口和实现类</h3><p>创建SYS_USERINFO（用户档案）、SYS_USER_ROLE（用户角色）、SYS_USER_PERMISSION（用户权限）、SYS_POST_USER（用户岗位）、SYS_USER_DEPARTMENT（用户部门）、SYS_PERMISSION（权限表）、SYS_DEPARTMENT（部门表）、SYS_MODULE（模块表）的接口和实现类</p>
<p><strong>IUserInfoManage、UserInfoManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> interface IUserInfoManage : IRepository&lt;Domain.SYS_USERINFO&gt;</span><br><span class="line">    &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层用户拓展信息接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserInfoManage</span> :</span> RepositoryBase&lt;Domain.SYS_USERINFO&gt;, IService.IUserInfoManage</span><br><span class="line">    &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IUserRoleManage、UserRoleManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层用户与角色关系接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IUserRoleManage : IRepository&lt;Domain.SYS_USER_ROLE&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 设置用户角色</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="roleId"&gt;角色ID字符串&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">SetUserRole</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> roleId)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层用户与角色关系接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserRoleManage</span> :</span> RepositoryBase&lt;Domain.SYS_USER_ROLE&gt;, IService.IUserRoleManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 设置用户角色</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="roleId"&gt;角色ID字符串,连接&lt;/param&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">SetUserRole</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> roleId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//1、删除用户角色</span></span><br><span class="line">                <span class="keyword">this</span>.Delete(p =&gt; p.FK_USERID == userId);</span><br><span class="line">                <span class="comment">//2、设置当前用户的角色</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">string</span>.IsNullOrEmpty(roleId)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">                foreach (var entity in roleId.Split(<span class="string">','</span>).Select(t =&gt; <span class="keyword">new</span> Domain.SYS_USER_ROLE()</span><br><span class="line">                &#123;</span><br><span class="line">                    FK_USERID = userId,</span><br><span class="line">                    FK_ROLEID = <span class="keyword">int</span>.Parse(t)</span><br><span class="line">                &#125;))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.dbSet.Add(entity);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">this</span>.Context.SaveChanges() &gt; <span class="number">0</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IPermissionManage、PermissionManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service 授权验证模块对应接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IPermissionManage : IRepository&lt;Domain.SYS_PERMISSION&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据系统ID获取所有模块的权限ID集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;<span class="keyword">int</span>&gt; GetPermissionIdBySysId(<span class="built_in">string</span> sysId);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Data.Common;</span><br><span class="line"><span class="keyword">using</span> System.Data.SqlClient;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service 授权模块关系处理类</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PermissionManage</span> :</span> RepositoryBase&lt;Domain.SYS_PERMISSION&gt;, IService.IPermissionManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据系统ID获取所有模块的权限ID集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;<span class="keyword">int</span>&gt; GetPermissionIdBySysId(<span class="built_in">string</span> sysId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">string</span> sql = <span class="string">"select p.id from sys_permission p where exists(select 1 from sys_module t where t.fk_belongsystem=@sysid and t.id=p.moduleid)"</span>;</span><br><span class="line">                DbParameter para = <span class="keyword">new</span> SqlParameter(<span class="string">"@sysid"</span>, sysId);</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">this</span>.SelectBySql&lt;<span class="keyword">int</span>&gt;(sql, para);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">throw</span> e;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IUserPermissionManage、UserPermissionManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层用户授权接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IUserPermissionManage : IRepository&lt;Domain.SYS_USER_PERMISSION&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 设置用户权限</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="newper"&gt;权限字符串&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="sysId"&gt;系统ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">SetUserPermission</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> newper, <span class="built_in">string</span> sysId)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> Service.IService;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层用户授权接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserPermissionManage</span> :</span> RepositoryBase&lt;Domain.SYS_USER_PERMISSION&gt;, IUserPermissionManage</span><br><span class="line">    &#123;</span><br><span class="line">        IPermissionManage PermissionManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 保存用户权限</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">SetUserPermission</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> newper, <span class="built_in">string</span> sysId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//1、获取当前系统的模块ID集合</span></span><br><span class="line">                var permissionId = <span class="keyword">this</span>.PermissionManage.GetPermissionIdBySysId(sysId).Cast&lt;<span class="keyword">int</span>&gt;().ToList();</span><br><span class="line">                <span class="comment">//2、获取用户权限，是否存在，存在即删除</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.IsExist(p =&gt; p.FK_USERID == userId &amp;&amp; permissionId.Any(e =&gt; e == p.FK_PERMISSIONID)))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//3、删除用户权限</span></span><br><span class="line">                    <span class="keyword">this</span>.Delete(p =&gt; p.FK_USERID == userId &amp;&amp; permissionId.Any(e =&gt; e == p.FK_PERMISSIONID));</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//4、添加用户权限</span></span><br><span class="line">                var str = newper.Trim(<span class="string">','</span>).Split(<span class="string">','</span>);</span><br><span class="line">                foreach (var per in str.Select(t =&gt; <span class="keyword">new</span> Domain.SYS_USER_PERMISSION()</span><br><span class="line">                &#123;</span><br><span class="line">                    FK_USERID = userId,</span><br><span class="line">                    FK_PERMISSIONID = <span class="keyword">int</span>.Parse(t)</span><br><span class="line">                &#125;))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.dbSet.Add(per);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//5、Save</span></span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">this</span>.Context.SaveChanges() &gt; <span class="number">0</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IPostUserManage、PostUserManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 岗位用户关系业务接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IPostUserManage : IRepository&lt;Domain.SYS_POST_USER&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据岗位ID获取人员集合，可传递多个岗位ID</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_USER&gt; GetUserListByPostId(<span class="built_in">string</span> postId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据人员ID获取岗位集合，可传递多个</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_POST&gt; GetPostListByUserId(<span class="built_in">string</span> userId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 添加岗位人员关系</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;人员ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="postId"&gt;岗位ID集合&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">SavePostUser</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> postId)</span></span>;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据岗位集合获取岗位名称，部门-岗位模式        </span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function">dynamic <span class="title">GetPostNameBySysPostUser</span><span class="params">(ICollection&lt;Domain.SYS_POST_USER&gt; collection)</span></span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 岗位人员关系业务实现类</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PostUserManage</span> :</span> RepositoryBase&lt;Domain.SYS_POST_USER&gt;, IService.IPostUserManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据岗位ID获取人员列表</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_USER&gt; GetUserListByPostId(<span class="built_in">string</span> postId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">string</span> sql = @<span class="string">"select * from sys_user t where exists(select u.fk_userid from sys_post_user u</span></span><br><span class="line"><span class="string">                                inner join sys_post_department p</span></span><br><span class="line"><span class="string">                                on u.fk_post_departmentid=p.id</span></span><br><span class="line"><span class="string">                                where t.id=u.fk_userid and p.fk_post_id in ("</span> + postId + <span class="string">")  group by u.fk_userid)"</span>;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">this</span>.SelectBySql&lt;Domain.SYS_USER&gt;(sql);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e.InnerException; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID获取所持有的岗位集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_POST&gt; GetPostListByUserId(<span class="built_in">string</span> userId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.LoadAll(p =&gt; userId.Contains(p.FK_USERID.ToString())).Select(p =&gt; p.SYS_POST_DEPARTMENT.SYS_POST).ToList();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 添加岗位人员关系</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;人员ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="postId"&gt;岗位ID集合&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">SavePostUser</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> postId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.IsExist(p =&gt; p.FK_USERID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//存在之后再对比是否一致</span></span><br><span class="line">                    var oldCount = <span class="keyword">this</span>.LoadAll(p =&gt; p.FK_USERID == userId).Select(p =&gt; p.FK_POST_DEPARTMENTID).ToList().Cast&lt;<span class="keyword">int</span>&gt;().ToList();</span><br><span class="line">                    var newpostId = postId.Trim(<span class="string">','</span>).Split(<span class="keyword">new</span> <span class="built_in">string</span>[] &#123; <span class="string">","</span> &#125;, StringSplitOptions.RemoveEmptyEntries).Select(p =&gt; <span class="keyword">int</span>.Parse(p)).ToList();</span><br><span class="line">                    <span class="keyword">if</span> (oldCount.Count == newpostId.Count &amp;&amp; oldCount.All(newpostId.Contains)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">                    <span class="comment">//删除原有关系</span></span><br><span class="line">                    <span class="keyword">this</span>.Delete(p =&gt; p.FK_USERID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(postId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//添加现有关系</span></span><br><span class="line">                    var <span class="built_in">list</span> = postId.Split(<span class="string">','</span>).Select(item =&gt; <span class="keyword">new</span> Domain.SYS_POST_USER()</span><br><span class="line">                    &#123;</span><br><span class="line">                        FK_USERID = userId,</span><br><span class="line">                        FK_POST_DEPARTMENTID = <span class="keyword">int</span>.Parse(item)</span><br><span class="line">                    &#125;).ToList();</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">this</span>.SaveList(<span class="built_in">list</span>) &gt; <span class="number">0</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e.InnerException; &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据岗位集合获取岗位名称，部门-岗位模式        </span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> dynamic <span class="title">GetPostNameBySysPostUser</span><span class="params">(ICollection&lt;Domain.SYS_POST_USER&gt; collection)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="comment">//岗位部门关系ID集合</span></span><br><span class="line">            <span class="built_in">string</span> post_departmentid = collection.Select(p =&gt; p.FK_POST_DEPARTMENTID).Aggregate(<span class="built_in">string</span>.Empty, (current, t) =&gt; current + <span class="string">"'"</span> + t + <span class="string">"',"</span>).TrimEnd(<span class="string">','</span>);</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">string</span> sql = @<span class="string">"select d.name+'-'+p.postname as postname,s.id from sys_department d inner join</span></span><br><span class="line"><span class="string">                        sys_post_department s on d.id=s.fk_department_id</span></span><br><span class="line"><span class="string">                        inner join sys_post p on p.id=s.fk_post_id</span></span><br><span class="line"><span class="string">                        where s.id in ("</span> + post_departmentid + <span class="string">")"</span>;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">this</span>.ExecuteSqlQuery(sql);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e.InnerException; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IUserDepartmentManage、UserDepartmentManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 用户部门关系业务接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IUserDepartmentManage : IRepository&lt;Domain.SYS_USER_DEPARTMENT&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID获取当前部门的所有用户集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_USER&gt; GetUserListByDptId(List&lt;<span class="built_in">string</span>&gt; dptId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID获取所在的部门集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_DEPARTMENT&gt; GetDptListByUserId(<span class="keyword">int</span> userId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 保存用户部门关系</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="dptId"&gt;部门ID集合&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">SaveUserDpt</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> dptId)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 用户部门关系业务实现类</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserDepartmentManage</span> :</span> RepositoryBase&lt;Domain.SYS_USER_DEPARTMENT&gt;, IService.IUserDepartmentManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID获取当前部门的所有用户ID集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_USER&gt; GetUserListByDptId(List&lt;<span class="built_in">string</span>&gt; dptId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.LoadAll(p =&gt; dptId.Contains(p.DEPARTMENT_ID)).Select(p =&gt; p.SYS_USER).ToList();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID获取所在的部门ID集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_DEPARTMENT&gt; GetDptListByUserId(<span class="keyword">int</span> userId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.LoadAll(p =&gt; p.USER_ID == userId).Select(p =&gt; p.SYS_DEPARTMENT).ToList();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 保存用户部门关系</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="dptId"&gt;部门ID集合&lt;/param&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">SaveUserDpt</span><span class="params">(<span class="keyword">int</span> userId, <span class="built_in">string</span> dptId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//原始部门人员关系是否与当前设置一致，不一致重新构造</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.IsExist(p =&gt; p.USER_ID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//存在之后再对比是否一致</span></span><br><span class="line">                    var oldCount = <span class="keyword">this</span>.LoadAll(p =&gt; p.USER_ID == userId &amp;&amp; dptId.Contains(p.DEPARTMENT_ID)).Select(p =&gt; p.DEPARTMENT_ID).ToList();</span><br><span class="line">                    var newdptid = dptId.Split(<span class="string">','</span>).OrderBy(c =&gt; c).ToList();</span><br><span class="line">                    <span class="keyword">if</span> (oldCount.Count == newdptid.Count &amp;&amp; oldCount.All(newdptid.Contains)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">                    <span class="comment">//删除原有关系</span></span><br><span class="line">                    <span class="keyword">this</span>.Delete(p =&gt; p.USER_ID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(dptId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//添加现有关系</span></span><br><span class="line">                    var <span class="built_in">list</span> = dptId.Split(<span class="string">','</span>).Select(item =&gt; <span class="keyword">new</span> Domain.SYS_USER_DEPARTMENT()</span><br><span class="line">                    &#123;</span><br><span class="line">                        DEPARTMENT_ID = item,</span><br><span class="line">                        USER_ID = userId</span><br><span class="line">                    &#125;).ToList();</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">this</span>.SaveList(<span class="built_in">list</span>) &gt; <span class="number">0</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e.InnerException; &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IDepartmentManage、DepartmentManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层部门管理接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IDepartmentManage : IRepository&lt;Domain.SYS_DEPARTMENT&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 递归部门列表，返回按级别排序</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="list"&gt;&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_DEPARTMENT&gt; RecursiveDepartment(List&lt;Domain.SYS_DEPARTMENT&gt; <span class="built_in">list</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID递归部门列表，返回子部门+本部门的对象集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_DEPARTMENT&gt; RecursiveDepartment(<span class="built_in">string</span> parentId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 自动创建部门编号</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="built_in">string</span> <span class="title">CreateCode</span><span class="params">(<span class="built_in">string</span> parentCode)</span></span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 部门是否存在下级部门</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">DepartmentIsExists</span><span class="params">(<span class="built_in">string</span> idlist)</span></span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID获取部门名称，不存在返回空</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="built_in">string</span> <span class="title">GetDepartmentName</span><span class="params">(<span class="built_in">string</span> id)</span></span>;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 显示错层方法</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function">object <span class="title">GetDepartmentName</span><span class="params">(<span class="built_in">string</span> name, decimal? level)</span></span>;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 获取部门父级列表</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        System.Collections.<span class="function">IList <span class="title">GetDepartmentByDetail</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> Common.JsonHelper;</span><br><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service层部门管理</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DepartmentManage</span> :</span> RepositoryBase&lt;Domain.SYS_DEPARTMENT&gt;, IService.IDepartmentManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 自动创建部门编号</span></span><br><span class="line">        <span class="comment">/// &lt;param name="parentId"&gt;上级部门ID 注：ID不是Code，数据表已改&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">string</span> <span class="title">CreateCode</span><span class="params">(<span class="built_in">string</span> parentId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="built_in">string</span> _strCode = <span class="built_in">string</span>.Empty;</span><br><span class="line"></span><br><span class="line">            <span class="meta">#region 验证上级部门code是否为空，为空返回，第一级部门的Code</span></span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">string</span>.IsNullOrEmpty(parentId))</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//注意：Oracle存储值为空=null MsSql 空=空 null=null</span></span><br><span class="line">                var query = <span class="keyword">this</span>.LoadAll(p =&gt; p.PARENTID == null || p.PARENTID == <span class="string">""</span>).OrderBy(p =&gt; p.CODE).ToList();</span><br><span class="line">                <span class="keyword">if</span> (!query.Any())</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="string">"001"</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//按照之前的逻辑，查漏补缺</span></span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= query.Count; i++)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="built_in">string</span> code = query[i - <span class="number">1</span>].CODE;</span><br><span class="line">                    <span class="keyword">if</span> (<span class="built_in">string</span>.IsNullOrEmpty(code))</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="keyword">return</span> FormatCode(i);</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">if</span> (i != <span class="keyword">int</span>.Parse(code))</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="keyword">return</span> FormatCode(i);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> FormatCode(query.Count + <span class="number">1</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="meta">#endregion</span></span><br><span class="line"></span><br><span class="line">            <span class="meta">#region 上级部门不为空,返回当前上级部门下的部门Code</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">/* *根据部门编号获取下级部门 查询条件为：</span></span><br><span class="line"><span class="comment">             * 1.下级部门编号长度=当前部门编号+3</span></span><br><span class="line"><span class="comment">             * 2.下级部门上级部门ID=当前部门ID</span></span><br><span class="line"><span class="comment">             * */</span></span><br><span class="line">            var parentDpt = <span class="keyword">this</span>.Get(p =&gt; p.ID == parentId);</span><br><span class="line">            <span class="keyword">if</span> (parentDpt != null)<span class="comment">//上级部门存在</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//查询同等级部门下的所有数据</span></span><br><span class="line">                var queryable = <span class="keyword">this</span>.LoadAll(p =&gt; p.CODE.Length == parentDpt.CODE.Length + <span class="number">3</span> &amp;&amp; p.PARENTID == parentId).OrderBy(p =&gt; p.CODE).ToList();</span><br><span class="line">                <span class="keyword">if</span> (queryable.Any())</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//需要验证是否存在编号缺失的情况 方法:遍历下级部门列表，</span></span><br><span class="line">                    <span class="comment">//用部门编号去掉上级部门编号，然后转化成数字和for循环的索引进行对比,遇到第一个不相等时，返回此编号，并跳出循环</span></span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= queryable.Count; i++)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="built_in">string</span> _code = queryable[i - <span class="number">1</span>].CODE;</span><br><span class="line">                        _code = _code.Substring(parentDpt.CODE.Length);</span><br><span class="line">                        <span class="keyword">int</span> _intCode = <span class="number">0</span>;</span><br><span class="line">                        Int32.TryParse(_code, out _intCode);</span><br><span class="line">                        <span class="comment">//下级部门编号中不存在</span></span><br><span class="line">                        <span class="keyword">if</span> (i != _intCode)</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="comment">//返回此编号,并退出循环</span></span><br><span class="line">                            _strCode = parentDpt.CODE + FormatCode(i);</span><br><span class="line">                            <span class="keyword">return</span> _strCode;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="comment">//不存在编号缺失情况</span></span><br><span class="line">                    _strCode = parentDpt.CODE + FormatCode(queryable.Count + <span class="number">1</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                &#123;</span><br><span class="line">                    _strCode = parentDpt.CODE + FormatCode(<span class="number">1</span>);</span><br><span class="line">                    <span class="keyword">return</span> _strCode;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="comment">//上级部门不存在，返回空，这种情况基本不会出现</span></span><br><span class="line">            <span class="meta">#endregion</span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> _strCode;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 功能描述:根据传入的数字 返回补码后的3位部门编号</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">string</span> <span class="title">FormatCode</span><span class="params">(<span class="keyword">int</span> dptCode)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">string</span> _strCode = <span class="built_in">string</span>.Empty;</span><br><span class="line">                <span class="comment">//&lt;=9 一位数</span></span><br><span class="line">                <span class="keyword">if</span> (dptCode &lt;= <span class="number">9</span> &amp;&amp; dptCode &gt;= <span class="number">1</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="string">"00"</span> + dptCode;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//&lt;=99 两位数</span></span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (dptCode &lt;= <span class="number">99</span> &amp;&amp; dptCode &gt; <span class="number">9</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="string">"0"</span> + dptCode;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//&lt;==999 三位数</span></span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (dptCode &lt;= <span class="number">999</span> &amp;&amp; dptCode &gt; <span class="number">99</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">return</span> _strCode;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="built_in">string</span>.Empty;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception ex)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">throw</span> ex;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 验证当前删除的部门是否存在下级部门</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">DepartmentIsExists</span><span class="params">(<span class="built_in">string</span> idlist)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.IsExist(p =&gt; idlist.Contains(p.PARENTID));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 递归部门列表，返回排序后的对象集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_DEPARTMENT&gt; RecursiveDepartment(List&lt;Domain.SYS_DEPARTMENT&gt; <span class="built_in">list</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            var result = <span class="keyword">new</span> List&lt;Domain.SYS_DEPARTMENT&gt;();</span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">list</span>.Count &gt; <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                ChildDepartment(<span class="built_in">list</span>, result, null);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> result;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID递归部门列表，返回子部门+本部门的对象集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_DEPARTMENT&gt; RecursiveDepartment(<span class="built_in">string</span> parentId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">//原始数据</span></span><br><span class="line">            var <span class="built_in">list</span> = <span class="keyword">this</span>.LoadAll(null);</span><br><span class="line">            <span class="comment">//新数据</span></span><br><span class="line">            var result = <span class="keyword">new</span> List&lt;Domain.SYS_DEPARTMENT&gt;();</span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">list</span>.Any())</span><br><span class="line">            &#123;</span><br><span class="line">                result.AddRange(<span class="built_in">list</span>.Where(p =&gt; p.ID == parentId).ToList());</span><br><span class="line">                <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(parentId))</span><br><span class="line">                    ChildDepartment(<span class="built_in">list</span>.ToList(), result, parentId);</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                    ChildDepartment(<span class="built_in">list</span>.ToList(), result, null);<span class="comment">//oracle使用null sql使用空</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> result;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">ChildDepartment</span><span class="params">(List&lt;Domain.SYS_DEPARTMENT&gt; newlist, List&lt;Domain.SYS_DEPARTMENT&gt; <span class="built_in">list</span>, <span class="built_in">string</span> id)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var result = newlist.Where(p =&gt; p.PARENTID == id).OrderBy(p =&gt; p.CODE).ThenBy(p =&gt; p.SHOWORDER).ToList();</span><br><span class="line">            <span class="keyword">if</span> (result.Any())</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; result.Count(); i++)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="built_in">list</span>.Add(result[i]);</span><br><span class="line">                    ChildDepartment(newlist, <span class="built_in">list</span>, result[i].ID);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据部门ID获取部门名称，不存在返回空</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">string</span> <span class="title">GetDepartmentName</span><span class="params">(<span class="built_in">string</span> id)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var query = <span class="keyword">this</span>.LoadAll(p =&gt; p.ID == id);</span><br><span class="line">            <span class="keyword">if</span> (query == null || !query.Any())</span><br><span class="line">                <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line">            <span class="keyword">return</span> query.First().NAME;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 显示错层方法</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> object <span class="title">GetDepartmentName</span><span class="params">(<span class="built_in">string</span> name, decimal? level)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">if</span> (level &gt; <span class="number">1</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">string</span> nbsp = <span class="string">"&amp;nbsp;&amp;nbsp;"</span>;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; level; i++)</span><br><span class="line">                &#123;</span><br><span class="line">                    nbsp += <span class="string">"&amp;nbsp;&amp;nbsp;"</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                name = nbsp + <span class="string">"|--"</span> + name;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> name;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 获取父级列表</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> IList <span class="title">GetDepartmentByDetail</span><span class="params">()</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var <span class="built_in">list</span> = RecursiveDepartment(<span class="keyword">this</span>.LoadAll(null).ToList())</span><br><span class="line">                .Select(p =&gt; <span class="keyword">new</span></span><br><span class="line">                &#123;</span><br><span class="line">                    id = p.ID,</span><br><span class="line">                    code = p.CODE,</span><br><span class="line">                    name = GetDepartmentName(p.NAME, p.BUSINESSLEVEL)</span><br><span class="line">                &#125;).ToList();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> JsonConverter.JsonClass(<span class="built_in">list</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>IModuleManage、ModuleManage</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.IService</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service模型处理接口</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> interface IModuleManage : IRepository&lt;Domain.SYS_MODULE&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 获取用户权限模块集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="permission"&gt;用户授权集合&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="siteId"&gt;站点ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_MODULE&gt; GetModule(<span class="keyword">int</span> userId, List&lt;Domain.SYS_PERMISSION&gt; permission, <span class="built_in">string</span> siteId);</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 递归模块列表，返回按级别排序</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        List&lt;Domain.SYS_MODULE&gt; RecursiveModule(List&lt;Domain.SYS_MODULE&gt; <span class="built_in">list</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 批量变更当前模块下其他模块的级别</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">MoreModifyModule</span><span class="params">(<span class="keyword">int</span> moduleId, <span class="keyword">int</span> levels)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> Common.JsonHelper;</span><br><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// Service模型处理类</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ModuleManage</span> :</span> RepositoryBase&lt;Domain.SYS_MODULE&gt;, IService.IModuleManage</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 获取用户权限模块集合</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userId"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="permission"&gt;用户授权集合&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="siteId"&gt;站点ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_MODULE&gt; GetModule(<span class="keyword">int</span> userId, List&lt;Domain.SYS_PERMISSION&gt; permission, <span class="built_in">string</span> siteId)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">//返回模块</span></span><br><span class="line">            var retmodule = <span class="keyword">new</span> List&lt;Domain.SYS_MODULE&gt;();</span><br><span class="line">            var permodule = <span class="keyword">new</span> List&lt;Domain.SYS_MODULE&gt;();</span><br><span class="line">            <span class="comment">//权限转模块</span></span><br><span class="line">            <span class="keyword">if</span> (permission != null)</span><br><span class="line">            &#123;</span><br><span class="line">                permodule.AddRange(permission.Select(p =&gt; p.SYS_MODULE));</span><br><span class="line">                <span class="comment">//去重</span></span><br><span class="line">                permodule = permodule.Distinct(<span class="keyword">new</span> ModuleDistinct()).ToList();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//检索显示与系统</span></span><br><span class="line">            <span class="comment">//permodule = permodule.Where(p =&gt; p.ISSHOW == 1 &amp;&amp; p.FK_BELONGSYSTEM.ToString() == siteId).ToList();</span></span><br><span class="line">            <span class="comment">//商城系统融入本系统不再区分系统</span></span><br><span class="line">            permodule = permodule.Where(p =&gt; p.ISSHOW == <span class="number">1</span>).ToList();</span><br><span class="line">            <span class="comment">//构造上级导航模块</span></span><br><span class="line">            <span class="comment">//var prevModule = this.LoadListAll(p =&gt; p.FK_BELONGSYSTEM.ToString() == siteId);</span></span><br><span class="line">            <span class="comment">//商城系统融入本系统不再区分系统</span></span><br><span class="line">            var prevModule = <span class="keyword">this</span>.LoadListAll(null);</span><br><span class="line">            <span class="comment">//反向递归算法构造模块带上级上上级模块</span></span><br><span class="line">            <span class="keyword">if</span> (permodule.Count &gt; <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                foreach (var item in permodule)</span><br><span class="line">                &#123;</span><br><span class="line">                    RecursiveModule(prevModule, retmodule, item.PARENTID);</span><br><span class="line">                    retmodule.Add(item);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//去重</span></span><br><span class="line">            retmodule = retmodule.Distinct(<span class="keyword">new</span> ModuleDistinct()).ToList();</span><br><span class="line">            <span class="comment">//返回模块集合</span></span><br><span class="line">            <span class="keyword">return</span> retmodule.OrderBy(p =&gt; p.LEVELS).ThenBy(p =&gt; p.SHOWORDER).ToList();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 反向递归模块集合，可重复模块数据，最后去重</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="PrevModule"&gt;总模块&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="retmodule"&gt;返回模块&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="parentId"&gt;上级ID&lt;/param&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">RecursiveModule</span><span class="params">(List&lt;Domain.SYS_MODULE&gt; PrevModule, List&lt;Domain.SYS_MODULE&gt; retmodule, <span class="keyword">int</span>? parentId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var result = PrevModule.Where(p =&gt; p.ID == parentId);</span><br><span class="line">            <span class="keyword">if</span> (result != null)</span><br><span class="line">            &#123;</span><br><span class="line">                foreach (var item in result)</span><br><span class="line">                &#123;</span><br><span class="line">                    retmodule.Add(item);</span><br><span class="line">                    RecursiveModule(PrevModule, retmodule, item.PARENTID);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 递归模块列表，返回按级别排序</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">public</span> List&lt;Domain.SYS_MODULE&gt; RecursiveModule(List&lt;Domain.SYS_MODULE&gt; <span class="built_in">list</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            List&lt;Domain.SYS_MODULE&gt; result = <span class="keyword">new</span> List&lt;Domain.SYS_MODULE&gt;();</span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">list</span> != null &amp;&amp; <span class="built_in">list</span>.Count &gt; <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                ChildModule(<span class="built_in">list</span>, result, <span class="number">0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> result;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 递归模块列表</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">ChildModule</span><span class="params">(List&lt;Domain.SYS_MODULE&gt; <span class="built_in">list</span>, List&lt;Domain.SYS_MODULE&gt; newlist, <span class="keyword">int</span> parentId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var result = <span class="built_in">list</span>.Where(p =&gt; p.PARENTID == parentId).OrderBy(p =&gt; p.LEVELS).OrderBy(p =&gt; p.SHOWORDER).ToList();</span><br><span class="line">            <span class="keyword">if</span> (result.Count() &gt; <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; result.Count(); i++)</span><br><span class="line">                &#123;</span><br><span class="line">                    newlist.Add(result[i]);</span><br><span class="line">                    ChildModule(<span class="built_in">list</span>, newlist, result[i].ID);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 批量变更下级模块的级别</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">MoreModifyModule</span><span class="params">(<span class="keyword">int</span> moduleId, <span class="keyword">int</span> levels)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="comment">//根据当前模块ID获取下级模块的集合</span></span><br><span class="line">            var ChildModule = <span class="keyword">this</span>.LoadAll(p =&gt; p.PARENTID == moduleId).ToList();</span><br><span class="line">            <span class="keyword">if</span> (ChildModule.Any())</span><br><span class="line">            &#123;</span><br><span class="line">                foreach (var item in ChildModule)</span><br><span class="line">                &#123;</span><br><span class="line">                    item.LEVELS = levels + <span class="number">1</span>;</span><br><span class="line">                    <span class="keyword">this</span>.Update(item);</span><br><span class="line">                    MoreModifyModule(item.ID, item.LEVELS);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 获取模板列表</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> dynamic <span class="title">LoadModuleInfo</span><span class="params">(<span class="keyword">int</span> id)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> JsonConverter.JsonClass(<span class="keyword">this</span>.LoadAll(p =&gt; p.PARENTID == id).OrderBy(p =&gt; p.ID).Select(p =&gt; <span class="keyword">new</span> &#123; p.ID, p.NAME &#125;).ToList());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 模型去重，非常重要</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ModuleDistinct</span> :</span> IEqualityComparer&lt;Domain.SYS_MODULE&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">Equals</span><span class="params">(Domain.SYS_MODULE x, Domain.SYS_MODULE y)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> x.ID == y.ID;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">GetHashCode</span><span class="params">(Domain.SYS_MODULE obj)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> obj.ToString().GetHashCode();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="四、修改UserManage实现类"><a href="#四、修改UserManage实现类" class="headerlink" title="四、修改UserManage实现类"></a>四、修改UserManage实现类</h3><p>为UserManage增加多个属性，后面通过Spring注入。最后增加权限去重class，暂时也放在UserManage类。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> Service.IService;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> Domain;</span><br><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> Common.JsonHelper;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> Service.ServiceImp</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserManage</span> :</span> RepositoryBase&lt;SYS_USER&gt;, IUserManage</span><br><span class="line">    &#123;</span><br><span class="line">        IDepartmentManage DepartmentManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IUserDepartmentManage UserDepartmentManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IUserInfoManage UserInfoManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IUserRoleManage UserRoleManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IUserPermissionManage UserPermissionManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IPostUserManage PostUserManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line">        IPermissionManage PermissionManage &#123; get; <span class="built_in">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 管理用户登录验证</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="userAccount"&gt;用户名&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="password"&gt;加密密码（AES）&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> SYS_USER <span class="title">UserLogin</span><span class="params">(<span class="built_in">string</span> userAccount, <span class="built_in">string</span> password)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var entity = <span class="keyword">this</span>.Get(p =&gt; p.ACCOUNT == userAccount);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//因为我们用的是AES的动态加密算法，也就是没有统一的密钥，那么两次同样字符串的加密结果是不一样的，所以这里要通过解密来匹配</span></span><br><span class="line">            <span class="comment">//而不能通过再次加密输入的密码来匹配</span></span><br><span class="line">            <span class="keyword">if</span> (entity != null &amp;&amp; <span class="keyword">new</span> Common.CryptHelper.AESCrypt().Decrypt(entity.PASSWORD) == password)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">return</span> entity;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> null;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 是否超级管理员</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">IsAdmin</span><span class="params">(<span class="keyword">int</span> userId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="comment">//通过用户ID获取角色</span></span><br><span class="line">            SYS_USER entity = <span class="keyword">this</span>.Get(p =&gt; p.ID == userId);</span><br><span class="line">            <span class="keyword">if</span> (entity == null) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">            var roles = entity.SYS_USER_ROLE.Select(p =&gt; <span class="keyword">new</span> SYS_ROLE</span><br><span class="line">            &#123;</span><br><span class="line">                ID = p.SYS_ROLE.ID</span><br><span class="line">            &#125;);</span><br><span class="line">            <span class="keyword">return</span> roles.ToList().Any(item =&gt; item.ID == Common.Enums.ClsDic.DicRole[<span class="string">"超级管理员"</span>]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID获取用户名</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;param name="Id"&gt;用户ID&lt;/param&gt;</span></span><br><span class="line">        <span class="comment">/// &lt;returns&gt;&lt;/returns&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">string</span> <span class="title">GetUserName</span><span class="params">(<span class="keyword">int</span> Id)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var query = <span class="keyword">this</span>.LoadAll(c =&gt; c.ID == Id);</span><br><span class="line">            <span class="keyword">if</span> (query == null || !query.Any())</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> query.First().NAME;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID获取部门名称</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">string</span> <span class="title">GetUserDptName</span><span class="params">(<span class="keyword">int</span> id)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">if</span> (id &lt;= <span class="number">0</span>)</span><br><span class="line">                <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line">            var dptid = <span class="keyword">this</span>.Get(p =&gt; p.ID == id).DPTID;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.DepartmentManage.Get(p =&gt; p.ID == dptid).NAME;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户ID删除用户相关记录</span></span><br><span class="line">        <span class="comment">/// 删除原则：1、删除用户档案</span></span><br><span class="line">        <span class="comment">///           2、删除用户角色关系</span></span><br><span class="line">        <span class="comment">///           3、删除用户权限关系</span></span><br><span class="line">        <span class="comment">///           4、删除用户岗位关系</span></span><br><span class="line">        <span class="comment">///           5、删除用户部门关系</span></span><br><span class="line">        <span class="comment">///           6、删除用户</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">Remove</span><span class="params">(<span class="keyword">int</span> userId)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">try</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//档案</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.UserInfoManage.IsExist(p =&gt; p.USERID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.UserInfoManage.Delete(p =&gt; p.USERID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//用户角色</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.UserRoleManage.IsExist(p =&gt; p.FK_USERID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.UserRoleManage.Delete(p =&gt; p.FK_USERID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//用户权限</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.UserPermissionManage.IsExist(p =&gt; p.FK_USERID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.UserPermissionManage.Delete(p =&gt; p.FK_USERID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//用户岗位</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.PostUserManage.IsExist(p =&gt; p.FK_USERID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.PostUserManage.Delete(p =&gt; p.FK_USERID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//用户部门</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.UserDepartmentManage.IsExist(p =&gt; p.USER_ID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.UserDepartmentManage.Delete(p =&gt; p.USER_ID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//用户自身</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.IsExist(p =&gt; p.ID == userId))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">this</span>.Delete(p =&gt; p.ID == userId);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">catch</span> (Exception e) &#123; <span class="keyword">throw</span> e.InnerException; &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户构造用户基本信息</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> Account <span class="title">GetAccountByUser</span><span class="params">(SYS_USER users)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">if</span> (users == null) <span class="keyword">return</span> null;</span><br><span class="line">            <span class="comment">//用户授权---&gt;注意用户的授权是包括角色权限与自身权限的</span></span><br><span class="line">            var permission = GetPermissionByUser(users);</span><br><span class="line">            <span class="comment">//用户角色</span></span><br><span class="line">            var role = users.SYS_USER_ROLE.Select(p =&gt; p.SYS_ROLE).ToList();</span><br><span class="line">            <span class="comment">//用户部门</span></span><br><span class="line">            var dpt = users.SYS_USER_DEPARTMENT.Select(p =&gt; p.SYS_DEPARTMENT).ToList();</span><br><span class="line">            <span class="comment">//用户岗位</span></span><br><span class="line">            var post = users.SYS_POST_USER.ToList();</span><br><span class="line">            <span class="comment">//用户主部门</span></span><br><span class="line">            var dptInfo = <span class="keyword">this</span>.DepartmentManage.Get(p =&gt; p.ID == users.DPTID);</span><br><span class="line">            <span class="comment">//用户模块</span></span><br><span class="line">            var <span class="keyword">module</span> = permission.Select(p =&gt; p.SYS_MODULE).ToList().Distinct(<span class="keyword">new</span> ModuleDistinct()).ToList();</span><br><span class="line">            Account account = <span class="keyword">new</span> Account()</span><br><span class="line">            &#123;</span><br><span class="line">                Id = users.ID,</span><br><span class="line">                Name = users.NAME,</span><br><span class="line">                LogName = users.ACCOUNT,</span><br><span class="line">                PassWord = users.PASSWORD,</span><br><span class="line">                IsAdmin = IsAdmin(users.ID),</span><br><span class="line">                DptInfo = dptInfo,</span><br><span class="line">                Dpt = dpt,</span><br><span class="line">                Face_Img = users.FACE_IMG,</span><br><span class="line">                Permissions = permission,</span><br><span class="line">                Roles = role,</span><br><span class="line">                PostUser = post,</span><br><span class="line">                Modules = <span class="keyword">module</span></span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="keyword">return</span> account;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 从Cookie中获取用户信息</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> Account <span class="title">GetAccountByCookie</span><span class="params">()</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            var cookie = Common.CookieHelper.GetCookie(<span class="string">"cookie_rememberme"</span>);</span><br><span class="line">            <span class="keyword">if</span> (cookie != null)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="comment">//验证json的有效性</span></span><br><span class="line">                <span class="keyword">if</span> (!<span class="built_in">string</span>.IsNullOrEmpty(cookie.Value))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//解密</span></span><br><span class="line">                    var cookievalue = <span class="keyword">new</span> Common.CryptHelper.AESCrypt().Decrypt(cookie.Value);</span><br><span class="line">                    <span class="comment">//是否为json</span></span><br><span class="line">                    <span class="keyword">if</span> (!JsonSplit.IsJson(cookievalue)) <span class="keyword">return</span> null;</span><br><span class="line">                    <span class="keyword">try</span></span><br><span class="line">                    &#123;</span><br><span class="line">                        var jsonFormat = JsonConverter.ConvertJson(cookievalue);</span><br><span class="line">                        <span class="keyword">if</span> (jsonFormat != null)</span><br><span class="line">                        &#123;</span><br><span class="line">                            var users = UserLogin(jsonFormat.username, <span class="keyword">new</span> Common.CryptHelper.AESCrypt().Decrypt(jsonFormat.password));</span><br><span class="line">                            <span class="keyword">if</span> (users != null)</span><br><span class="line">                                <span class="keyword">return</span> GetAccountByUser(users);</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">catch</span> &#123; <span class="keyword">return</span> null; &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> null;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">        <span class="comment">/// 根据用户信息获取用户所有的权限</span></span><br><span class="line">        <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">        <span class="keyword">private</span> List&lt;SYS_PERMISSION&gt; GetPermissionByUser(SYS_USER users)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">//1、超级管理员拥有所有权限</span></span><br><span class="line">            <span class="keyword">if</span> (IsAdmin(users.ID))</span><br><span class="line">                <span class="keyword">return</span> PermissionManage.LoadListAll(null);</span><br><span class="line">            <span class="comment">//2、普通用户，合并当前用户权限与角色权限</span></span><br><span class="line">            var perlist = <span class="keyword">new</span> List&lt;SYS_PERMISSION&gt;();</span><br><span class="line">            <span class="comment">//2.1合并用户权限</span></span><br><span class="line">            perlist.AddRange(users.SYS_USER_PERMISSION.Select(p =&gt; p.SYS_PERMISSION).ToList());</span><br><span class="line">            <span class="comment">//2.2合同角色权限</span></span><br><span class="line">            <span class="comment">////todo:经典多对多的数据查询Linq方法</span></span><br><span class="line">            perlist.AddRange(users.SYS_USER_ROLE.Select(p =&gt; p.SYS_ROLE.SYS_ROLE_PERMISSION.Select(c =&gt; c.SYS_PERMISSION)).SelectMany(c =&gt; c.Select(e =&gt; e)).Cast&lt;SYS_PERMISSION&gt;().ToList());</span><br><span class="line">            <span class="comment">//3、去重</span></span><br><span class="line">            <span class="comment">////todo:通过重写IEqualityComparer&lt;T&gt;实现对象去重</span></span><br><span class="line">            perlist = perlist.Distinct(<span class="keyword">new</span> PermissionDistinct()).ToList();</span><br><span class="line">            <span class="keyword">return</span> perlist;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/// &lt;summary&gt;</span></span><br><span class="line">    <span class="comment">/// 权限去重，非常重要</span></span><br><span class="line">    <span class="comment">/// &lt;/summary&gt;</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PermissionDistinct</span> :</span> IEqualityComparer&lt;SYS_PERMISSION&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">Equals</span><span class="params">(SYS_PERMISSION x, SYS_PERMISSION y)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> x.ID == y.ID;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">GetHashCode</span><span class="params">(SYS_PERMISSION obj)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> obj.ToString().GetHashCode();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="五、修改spring配置-Service-Config-Service-xml"><a href="#五、修改spring配置-Service-Config-Service-xml" class="headerlink" title="五、修改spring配置(Service/Config/Service.xml)"></a>五、修改spring配置(Service/Config/Service.xml)</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--系统管理begin--&gt;</span></span><br><span class="line"><span class="comment">&lt;!--用户管理--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.User"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.UserManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"UserInfoManage"</span> <span class="attr">ref</span>=<span class="string">"Service.UserInfo"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"UserRoleManage"</span> <span class="attr">ref</span>=<span class="string">"Service.UserRole"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"UserPermissionManage"</span> <span class="attr">ref</span>=<span class="string">"Service.UserPermission"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"PostUserManage"</span> <span class="attr">ref</span>=<span class="string">"Service.PostUser"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"PermissionManage"</span> <span class="attr">ref</span>=<span class="string">"Service.Permission"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"DepartmentManage"</span> <span class="attr">ref</span>=<span class="string">"Service.Department"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"UserDepartmentManage"</span> <span class="attr">ref</span>=<span class="string">"Service.UserDepartment"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.Module"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.ModuleManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.UserInfo"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.UserInfoManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.UserRole"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.UserRoleManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.PostUser"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.PostUserManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.UserPermission"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.UserPermissionManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.Permission"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.PermissionManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.Department"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.DepartmentManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">object</span> <span class="attr">id</span>=<span class="string">"Service.UserDepartment"</span> <span class="attr">type</span>=<span class="string">"Service.ServiceImp.UserDepartmentManage,Service"</span> <span class="attr">singleton</span>=<span class="string">"false"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">object</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--系统管理end--&gt;</span></span><br></pre></td></tr></table></figure>

                <!-- <hr> -->
                

                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/2017/02/17/mvc-lesson6/" data-toggle="tooltip" data-placement="top"
                           title="Asp.net MVC系列教程6——丰富数据表、建立关联">&larr; Previous Post</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/2017/02/20/mvc-lesson8/" data-toggle="tooltip" data-placement="top"
                           title="Asp.net MVC系列教程8——完善登录功能">Next Post &rarr;</a>
                    </li>
                    
                </ul>

                <!-- social-share start -->
                <div class="social-share" style="padding-top:20px;text-align:center;"></div>
                <!--  css & js -->
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css
                ">
                <script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>
                <!-- social-share end -->


                

                
                <!-- disqus 评论框 start -->
                <div class="comment">
                    <div id="disqus_thread" class="disqus-thread"></div>
                </div>
                <!-- disqus 评论框 end -->
                

            </div>

            <div class="hidden-xs col-sm-3 toc-col">
                <div class="toc-wrap">
                    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#简述"><span class="toc-text">简述</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#索引"><span class="toc-text">索引</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#项目开始"><span class="toc-text">项目开始</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#一、新建登录用户类Account"><span class="toc-text">一、新建登录用户类Account</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#二、修改我们的用户管理接口IUserManage"><span class="toc-text">二、修改我们的用户管理接口IUserManage</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三、我们分别创建几个关联表的接口和实现类"><span class="toc-text">三、我们分别创建几个关联表的接口和实现类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#四、修改UserManage实现类"><span class="toc-text">四、修改UserManage实现类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#五、修改spring配置-Service-Config-Service-xml"><span class="toc-text">五、修改spring配置(Service/Config/Service.xml)</span></a></li></ol></li></ol></li></ol>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                
                <section>
                    <!-- no hr -->
                    <h5 class="text-center">
                        <a href="/tags/">FEATURED TAGS</a>
                    </h5>
                    <div class="tags">
                        
                        <a class="tag" href="/tags/#c#"
                           title="c#">c#</a>
                        
                    </div>
                </section>
                

                <!-- Friends Blog -->
                
            </div>
        </div>

    </div>
</article>

<div id="music">
    <audio id="bell" src="/music/Faded.mp3" preload="auto" loop autoplay></audio>
</div>
<!-- <embed style="position:fixed;right:0;bottom:0;"; src="http://www.xiami.com/widget/274513503_1776204257/singlePlayer.swf" type="application/x-shockwave-flash" width="257" height="33" wmode="transparent"></embed> -->
<!-- <embed style="position:fixed;right:0;bottom:-44px;"; src="http://www.xiami.com/widget/274513503_1775988866,1774426379,1770760772,1772121439,3567313,_235_246_FF8719_494949/multiPlayer.swf" allowscriptaccess="always" quality="high" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="235" height="246" title="Adobe Flash Player"> -->
<!-- music control -->
<script src="/js/music.js"></script>

<div class="gotoTop"></div>
<script src="/js/gotoTop.js"></script>



<!-- disqus 公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES * * */
    var disqus_shortname = "guanghuiwang";
    var disqus_identifier = "https://wghglory.github.io/2017/02/19/mvc-lesson7/";
    var disqus_url = "https://wghglory.github.io/2017/02/19/mvc-lesson7/";

    (function () {
        var dsq = document.createElement('script');
        dsq.type = 'text/javascript';
        dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<!-- disqus 公共JS代码 end -->



<!-- Footer -->
<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <br>
                <ul class="list-inline text-center">
                
                
                

                

                
                <li>
                    <a target="_blank" href="https://www.jianshu.com/u/85d2cacc9fcd">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-stack-1x fa-inverse">简</i>
                                </span>
                    </a>
                </li>
                

                
                    <li>
                        <a target="_blank" href="https://www.facebook.com/wghglory">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank"  href="https://github.com/wghglory">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank"  href="https://www.linkedin.com/in/guanghuiwang">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                </ul>
                <p class="copyright text-muted">
                    Copyright &copy; Guanghui 2017
                    <br>
                    <span id="busuanzi_container_site_pv" style="font-size: 12px;">PV: <span id="busuanzi_value_site_pv"></span> Times</span>
                    <br>
                    Modified theme based on <a href="https://haojen.github.io/">Haojen Ma</a>' Anisina
                </p>

            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/blog.js"></script>

<!-- code block fold/unfold button and copy button -->
<script src="/js/codeBlockEnhance.js"></script>

<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("https://wghglory.github.io/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>

<!-- Google Analytics -->


<script>
    // dynamic User by Hux
    var _gaId = 'UA-91771069-1';
    var _gaDomain = 'wghglory.github.io';
    // Originial
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', _gaId, _gaDomain);
    ga('send', 'pageview');
</script>


<!-- Baidu Tongji -->


<!-- swiftype -->
<script type="text/javascript">
  // (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
  // (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
  // e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  // })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
  //
  // _st('install','undefined','2.0.0');
</script>

<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<!--wechat title img-->
<img class="wechat-title-img" src="/images/avatar.jpg">
</body>

</html>
